# main.py
from graph import Graph
from visualizer import Visualizer

def create_grid_graph(rows=10, cols=10):
    """创建一个网格图，节点编号：0 ~ 99"""
    total = rows * cols
    g = Graph(total)
    pos = {}

    for r in range(rows):
        for c in range(cols):
            node = r * cols + c
            # 布局位置
            pos[node] = (c * 60 + 100, r * 60 + 100)

            # 添加上下左右边（避免越界）
            if r > 0:
                neighbor = (r - 1) * cols + c
                g.add_edge(node, neighbor, 1)
            if r < rows - 1:
                neighbor = (r + 1) * cols + c
                g.add_edge(node, neighbor, 1)
            if c > 0:
                neighbor = r * cols + (c - 1)
                g.add_edge(node, neighbor, 1)
            if c < cols - 1:
                neighbor = r * cols + (c + 1)
                g.add_edge(node, neighbor, 1)

    return g, pos

def main():
    ROWS, COLS = 10, 10
    g, pos = create_grid_graph(ROWS, COLS)

    # 起点和终点（初始）
    start_node = 0
    end_node = ROWS * COLS - 1  # 99

    # 启动可视化器
    vis = Visualizer(g, pos, width=1200, height=800, start_node=start_node, end_node=end_node)
    vis.run_selection_ui()

if __name__ == "__main__":
    main()
